package deng.qiya.biz;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

import deng.qiya.model.ClsCrsCommentTrans;
import deng.qiya.model.ClsCrsMyHisSource;
import deng.qiya.model.CommentTransHisInput;
import deng.qiya.model.HotelCommentInputParms;
import deng.qiya.model.clsCrsMyHisComment;


public class HotelComment {

	
	public static String GetHotelCommentInputParmsToXml(HotelCommentInputParms hotelCommentInput)
	{
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("HotelCommentInputParms", HotelCommentInputParms.class);
		xstream.aliasField("bolGuestIdentification", HotelCommentInputParms.class, "bolGuestIdentification");
		xstream.aliasField("datArrD", HotelCommentInputParms.class, "datArrD");
		xstream.aliasField("datDepD", HotelCommentInputParms.class, "datDepD");
		xstream.aliasField("intCustomerType", HotelCommentInputParms.class, "intCustomerType");
		xstream.aliasField("intOrderNo", HotelCommentInputParms.class, "intOrderNo");
		xstream.aliasField("shortCleanGrade", HotelCommentInputParms.class, "shortCleanGrade");
		xstream.aliasField("shortServiceGrade", HotelCommentInputParms.class, "shortServiceGrade");
		xstream.aliasField("shortShowerGrade", HotelCommentInputParms.class, "shortShowerGrade");
		xstream.aliasField("shortSleepGrade", HotelCommentInputParms.class,"shortSleepGrade");
		xstream.aliasField("strCommentID", HotelCommentInputParms.class, "strCommentID");
		xstream.aliasField("strCommentType", HotelCommentInputParms.class, "strCommentType");
		xstream.aliasField("strContent", HotelCommentInputParms.class, "strContent");
		xstream.aliasField("strCtfNo", HotelCommentInputParms.class, "strCtfNo");
		xstream.aliasField("strCtfTp", HotelCommentInputParms.class, "strCtfTp");
		xstream.aliasField("strHotelCd", HotelCommentInputParms.class, "strHotelCd");
		xstream.aliasField("strLisence", HotelCommentInputParms.class, "strLisence");
		xstream.aliasField("strMemberNo", HotelCommentInputParms.class, "strMemberNo");
		
		
		return xstream.toXML(hotelCommentInput);
		
	}

	
	public static String getCommentTransHisInputToXml(CommentTransHisInput commentTransHis)
	{
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("HotelCommentInputParms", CommentTransHisInput.class);
		xstream.aliasField("dtEnd", CommentTransHisInput.class, "dtEnd");
		xstream.aliasField("dtStart", CommentTransHisInput.class, "dtStart");
		xstream.aliasField("sCtfno", CommentTransHisInput.class, "sCtfno");
		xstream.aliasField("sCtftp", CommentTransHisInput.class, "sCtftp");
		xstream.aliasField("sHotelCd", CommentTransHisInput.class, "sHotelCd");
		xstream.aliasField("sLisence", CommentTransHisInput.class, "sLisence");
		
		return xstream.toXML(commentTransHis);
		
	}
	
	public static List<clsCrsMyHisComment> GetJsonToclsCrsMyHisComment(String json)
	{
		List<clsCrsMyHisComment> list = new ArrayList<clsCrsMyHisComment>();
		JSONParser parser = new JSONParser();
		try {
			JSONArray jsonArray = (JSONArray)parser.parse(json);
			@SuppressWarnings("rawtypes")
			Iterator it = jsonArray.iterator();
			while (it.hasNext()) {
				clsCrsMyHisComment rate = new clsCrsMyHisComment();
				JSONObject jo = (JSONObject)it.next();
				rate.setsArrD((String)jo.get("sArrD"));
				rate.setsCleanGrade((String)jo.get("sCleanGrade"));
				rate.setsCommentDate((String)jo.get("sCommentDate"));
				rate.setsCommentID((String)jo.get("sCommentID"));
				rate.setsCommentStatus((String)jo.get("sCommentStatus"));
				rate.setsCommentType((String)jo.get("sCommentType"));
				rate.setsContent((String)jo.get("sContent"));
				rate.setsCSPublishFlag((String)jo.get("sCSPublishFlag"));
				rate.setsCSReplyCCoprNumb((String)jo.get("sCSReplyCCoprNumb"));
				rate.setsCSReplyContent((String)jo.get("sCSReplyContent"));
				rate.setsCSReplyDate((String)jo.get("sCSReplyDate"));
				rate.setsCSReplyFlag((String)jo.get("sCSReplyFlag"));
				rate.setsCtfNo((String)jo.get("sCtfNo"));
				rate.setsCtfTp((String)jo.get("sCtfTp"));
				rate.setsCustomerType((String)jo.get("sCustomerType"));
				rate.setsDepD((String)jo.get("sDepD"));
				rate.setsGustNm((String)jo.get("sGustNm"));
				rate.setsHotelCd((String)jo.get("sHotelCd"));
				rate.setsHotelPublishFlag((String)jo.get("sHotelPublishFlag"));
				rate.setsHotelReplyCCOprNumb((String)jo.get("sHotelReplyCCOprNumb"));
				rate.setsHotelReplyContent((String)jo.get("sHotelReplyContent"));
				rate.setsHotelReplyDate((String)jo.get("sHotelReplyDate"));
				rate.setsHotelReplyFlag((String)jo.get("sHotelReplyFlag"));
				rate.setsHotelReplyStatus((String)jo.get("sHotelReplyStatus"));
				rate.setsID((String)jo.get("sID"));
				rate.setsMemberNo((String)jo.get("sMemberNo"));
				rate.setsMemberType((String)jo.get("sMemberType"));
				rate.setsMobile((String)jo.get("sMobile"));
				rate.setsOperationPublishFlag((String)jo.get("sOperationPublishFlag"));
				rate.setsOperationReplyCCOprNumb((String)jo.get("sOperationReplyCCOprNumb"));
				rate.setsOperationReplyContent((String)jo.get("sOperationReplyContent"));
				rate.setsOperationReplyDate((String)jo.get("sOperationReplyDate"));
				rate.setsOperationReplyFlag((String)jo.get("sOperationReplyFlag"));
				rate.setsOrderNo((String)jo.get("sOrderNo"));
				rate.setsPublishFlag((String)jo.get("sPublishFlag"));
				rate.setsServiceGrade((String)jo.get("sServiceGrade"));
				rate.setsShowerGrade((String)jo.get("sShowerGrade"));
				rate.setsSleepGrade((String)jo.get("sSleepGrade"));
				rate.setsSummary((String)jo.get("sSummary"));
				rate.setsWorkedFlag((String)jo.get("sWorkedFlag"));
				rate.setsWorkStatus((String)jo.get("sWorkStatus"));
				list.add(rate);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return list;
		
	}

	public static  List<ClsCrsMyHisSource>  GetJsonToClsCrsMyHisSource(String json)
	{
		
		List<ClsCrsMyHisSource> list = new ArrayList<ClsCrsMyHisSource>();
		JSONParser parser = new JSONParser();
		try {
			JSONArray jsonArray = (JSONArray)parser.parse(json);
			@SuppressWarnings("rawtypes")
			Iterator it = jsonArray.iterator();
			while (it.hasNext()) {
				ClsCrsMyHisSource rate = new ClsCrsMyHisSource();
				JSONObject jo = (JSONObject)it.next();
				rate.setsActualrt((String)jo.get("s_Actualrt"));
				rate.setsArrd((String)jo.get("s_Arrd"));
				rate.setsCtfNo((String)jo.get("s_CtfNo"));
				rate.setsCtfTp((String)jo.get("s_CtfTp"));
				rate.setsDepd((String)jo.get("s_Depd"));
				rate.setsHotelCd((String)jo.get("s_HotelCd"));
				
				rate.setsHotelName((String)jo.get("s_HotelName"));
				rate.setsNote((String)jo.get("s_Note"));
				rate.setsPrintRt((String)jo.get("s_PrintRt"));
				rate.setsRmTp((String)jo.get("s_RmTp"));
				
				
				list.add(rate);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return list;
	}

	public static List<ClsCrsCommentTrans> getJsonToClsCrsCommentTrans(String json)
	{
		List<ClsCrsCommentTrans> list = new ArrayList<ClsCrsCommentTrans>();
		JSONParser parser = new JSONParser();
		try {
			JSONArray jsonArray = (JSONArray)parser.parse(json);
			@SuppressWarnings("rawtypes")
			Iterator it = jsonArray.iterator();
			while (it.hasNext()) {
				ClsCrsCommentTrans rate = new ClsCrsCommentTrans();
				JSONObject jo = (JSONObject)it.next();
				rate.setsAcctNo((String)jo.get("sAcctNo"));
				rate.setsActualRt((String)jo.get("sActualRt"));
				rate.setsAddNm((String)jo.get("sAddNm"));
				rate.setsAddr((String)jo.get("sAddr"));
				rate.setsArrD((String)jo.get("sArrD"));
				rate.setsBirthday((String)jo.get("sBirthday"));
				rate.setsBookingNo((String)jo.get("sBookingNo"));
				rate.setsCompany((String)jo.get("sCompany"));
				rate.setsConbination((String)jo.get("sConbination"));
				rate.setsCRSResvNo((String)jo.get("sCRSResvNo"));
				rate.setsCtfNo((String)jo.get("sCtfNo"));
				rate.setsCtfTp((String)jo.get("sCtfTp"));
				rate.setsDepD((String)jo.get("sDepD"));
				rate.setsFirstName((String)jo.get("sFirstName"));
				rate.setsGender((String)jo.get("sGender"));
				rate.setsGrpNm((String)jo.get("sGrpNm"));
				rate.setsGrpNo((String)jo.get("sGrpNo"));
				rate.setsGustKind((String)jo.get("sGustKind"));
				rate.setsGustNm((String)jo.get("sGustNm"));
				rate.setsGustTp((String)jo.get("sGustTp"));
				rate.setsHotelCd((String)jo.get("sHotelCd"));
				rate.setsLanguage((String)jo.get("sLanguage"));
				rate.setsLastName((String)jo.get("sLastName"));
				rate.setsMemberNo((String)jo.get("sMemberNo"));
				rate.setsNation((String)jo.get("sNation"));
				rate.setsNationality((String)jo.get("sNationality"));
				rate.setsNote1((String)jo.get("sNote1"));
				rate.setsNote2((String)jo.get("sNote2"));
				rate.setsPrintRt((String)jo.get("sPrintRt"));
				rate.setsRegion1((String)jo.get("sRegion1"));
				rate.setsRegion2((String)jo.get("sRegion2"));
				rate.setsResvNo((String)jo.get("sResvNo"));
				rate.setsResvTime((String)jo.get("sResvTime"));
				rate.setsRmTp((String)jo.get("sRmTp"));
				rate.setsRtCd((String)jo.get("sRtCd"));
				rate.setsStayReason((String)jo.get("sStayReason"));
				rate.setsTAAcct((String)jo.get("sTAAcct"));
				rate.setsTel((String)jo.get("sTel"));
				rate.setsTitle((String)jo.get("sTitle"));
				rate.setsTotalXF((String)jo.get("sTotalXF"));
				rate.setsVipCd((String)jo.get("sVipCd"));
				rate.setsVisaTp((String)jo.get("sVisaTp"));
				rate.setsZip((String)jo.get("sZip"));
				
				list.add(rate);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return list;
		
	}
}
